﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class dba : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        /*if (File.Exists(@"D:\wwwnew\tupianshangchuan\tupianshangchuan\image\179.jpg") == false) //不存在该图片文件
        {
            Image1.ImageUrl = Server.MapPath("~/image/") + "179.jpg";
        }
        else //存在该图片文件 
        {
            Image1.ImageUrl = Server.MapPath("~/image/") + "touxiang.jpg";
        }*/
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
       
            DataClassesDataContext a1 = new DataClassesDataContext();
            string time = DateTime.Now.ToString();
            int num2 = Convert.ToInt32(TextBox17.Text);
            a1.insert_product(TextBox12.Text, TextBox13.Text, TextBox14.Text, TextBox15.Text, TextBox16.Text, time, "~/picture/" + FileUpload1.FileName, num2);
            Response.Write("<script>alert('信息已录入！');location='dba.aspx'</script>");

            //this.Image1.ImageUrl = "~/picture/" + FileUpload1.FileName;
            //TextBox1.Text = FileUpload1.FileName;
            // this.FileUpload1.SaveAs(Request.PhysicalApplicationPath+"\\"+"123\\" + FileUpload1.FileName);
        
    }
    protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
    {
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            System.Web.UI.WebControls.CheckBox checkbox = (System.Web.UI.WebControls.CheckBox)GridView1.Rows[i].FindControl("checkbox1");
            if (CheckBox2.Checked == true)
            {
                checkbox.Checked = true;
            }
            else
            {
                checkbox.Checked = false;
            }
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow gr in GridView1.Rows)
        {

                TextBox prod1 = (TextBox)gr.Cells[0].FindControl("TextBox6");
                TextBox prod2 = (TextBox)gr.Cells[1].FindControl("TextBox7");
                TextBox prod3 = (TextBox)gr.Cells[2].FindControl("TextBox8");
                TextBox prod4 = (TextBox)gr.Cells[3].FindControl("TextBox9");
                TextBox prod5 = (TextBox)gr.Cells[4].FindControl("TextBox10");
                TextBox num1 = (TextBox)gr.Cells[5].FindControl("TextBox11");
                int num2 = Convert.ToInt32(num1.Text);
                DataClassesDataContext a1 = new DataClassesDataContext();
                a1.update_porduct(prod1.Text,prod2.Text,prod3.Text,prod4.Text,prod5.Text,num2);
                //Response.Write(num1);
                
        }
        Response.Write("<script>alert('信息已更新！');location='dba.aspx'</script>");
    
    }
    protected void Button3_Click(object sender, EventArgs e)
    {

        foreach (GridViewRow gr in GridView1.Rows)
        {
            CheckBox c1 = (CheckBox)gr.FindControl("CheckBox1");
            if (c1.Checked)
            {
                TextBox prod1 = (TextBox)gr.Cells[2].FindControl("TextBox8");
                DataClassesDataContext a1 = new DataClassesDataContext();
                a1.delete_product(prod1.Text);
            }

        }
        Response.Write("<script>alert('删除成功！');location='dba.aspx'</script>");
        //GridView1.DataBind();
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        bool Files = false;
        //判断文件的类型是否符合要求
        if (this.FileUpload1.HasFile)
        {
            //获取删除文件的后缀
            string fileSuffix = System.IO.Path.GetExtension(this.FileUpload1.FileName).ToLower();
            string[] Suffix = { ".jpg", ".bmp", ".gif", ".png" };
            //判断文件是否符合要求
            for (int i = 0; i < Suffix.Length; i++)
            {
                if (fileSuffix == Suffix[i])
                {
                    Files = true;
                }
            }
        }

        //如果符合要求就上传,并显示信息
        if (Files == true)
        {
            //this.Image1.ImageUrl = "~/imager/" + FileUpload1.FileName;
            this.FileUpload1.SaveAs(Server.MapPath("~/picture/") + FileUpload1.FileName);
           /* DataClassesDataContext a1 = new DataClassesDataContext();
            string time = DateTime.Now.ToString();
            int num2 = Convert.ToInt32(TextBox17.Text);
            a1.insert_product(TextBox12.Text, TextBox13.Text, TextBox14.Text, TextBox15.Text, TextBox16.Text, time, "~/picture/" + FileUpload1.FileName, num2);
            Response.Write("<script>alert('信息已录入！');location='dba.aspx'</script>");*/

            this.Image1.ImageUrl = "~/picture/" + FileUpload1.FileName;
            //TextBox1.Text = FileUpload1.FileName;
            // this.FileUpload1.SaveAs(Request.PhysicalApplicationPath+"\\"+"123\\" + FileUpload1.FileName);
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('文件上传失败！');</script>");

        }
    }
}